#include "Panel.h"

IwNUINew::CPanelNew::CPanelNew() : CView()
{
	m_activeBackgroupImage = false;
}

IwNUINew::CPanelNew::CPanelNew( const CAttributes& attr ) : CView(attr)
{
	m_activeBackgroupImage = false;
}

IwNUINew::CPanelNew::~CPanelNew()
{

}

IwNUINew::CPanelNewPtr IwNUINew::CPanelNew::Create()
{
	return IwNUI::CSharedPtr<CPanelNew>(new CPanelNew());
}

IwNUINew::CPanelNewPtr IwNUINew::CPanelNew::Create( const CAttributes& attr )
{
	return IwNUI::CSharedPtr<CPanelNew>(new CPanelNew(attr));
}

void IwNUINew::CPanelNew::SetBackgroupColor( int r, int b, int g, int alpha )
{
	this->SetAttribute("backgroundColour", CColour(r, g, b, alpha));
}

void IwNUINew::CPanelNew::SetBackgroupColor( const CColour& color )
{
	this->SetAttribute("backgroundColour", color);
}

void IwNUINew::CPanelNew::SetBackgroupImage( const char* imageName )
{
	if(!m_activeBackgroupImage)
	{
		m_backgroupImage->Create();
		m_activeBackgroupImage = true;
		this->AddChild(m_backgroupImage);
	}

	m_backgroupImage->SetAttribute("image", imageName);
	m_backgroupImage->SetAttribute("x1", GetX1());
	m_backgroupImage->SetAttribute("y1", GetY1());
	
#ifdef MODIFY_WIDTH_HEIGHT_BGIMAGE
	m_backgroupImage->SetAttribute("width", GetWidth());
	m_backgroupImage->SetAttribute("height", GetHeight());
#endif
}

void IwNUINew::CPanelNew::ShowBackgroupImage( bool show )
{
	if(m_activeBackgroupImage)
	{
		if(show)
			this->RemoveChild(m_backgroupImage);
		else
			this->AddChild(m_backgroupImage);
	}
}

int IwNUINew::CPanelNew::GetX1()
{
	int x;
	this->GetAttribute("x1", x);
	return x;
}

void IwNUINew::CPanelNew::SetX1( int x )
{
	this->SetAttribute("x1", x);
	if(m_activeBackgroupImage)
		m_backgroupImage->SetAttribute("x1", x);
}

void IwNUINew::CPanelNew::SetX1( const char* x )
{
	this->SetAttribute("x1", x);
	if(m_activeBackgroupImage)
		m_backgroupImage->SetAttribute("x1", x);
}

int IwNUINew::CPanelNew::GetY1()
{
	int y;
	this->GetAttribute("y1", y);
	return y;
}

void IwNUINew::CPanelNew::SetY1( int y )
{
	this->SetAttribute("y1", y);
	if(m_activeBackgroupImage)
		m_backgroupImage->SetAttribute("y1", y);
}

void IwNUINew::CPanelNew::SetY1( const char* y )
{
	this->SetAttribute("y1", y);
	if(m_activeBackgroupImage)
		m_backgroupImage->SetAttribute("y1", y);
}

int IwNUINew::CPanelNew::GetWidth()
{
	int w;
	this->GetAttribute("width", w);
	return w;
}

void IwNUINew::CPanelNew::SetWidth( int w )
{
	this->SetAttribute("width", w);
#ifdef MODIFY_WIDTH_HEIGHT_BGIMAGE
	if(m_activeBackgroupImage)
		m_backgroupImage->SetAttribute("width", w);
#endif
}

void IwNUINew::CPanelNew::SetWidth( const char* w )
{
	this->SetAttribute("width", w);
#ifdef MODIFY_WIDTH_HEIGHT_BGIMAGE
	if(m_activeBackgroupImage)
		m_backgroupImage->SetAttribute("width", w);
#endif
}

int IwNUINew::CPanelNew::GetHeight()
{
	int h;
	this->GetAttribute("height", h);
	return h;
}

void IwNUINew::CPanelNew::SetHeight( int h )
{
	this->SetAttribute("height", h);
#ifdef MODIFY_WIDTH_HEIGHT_BGIMAGE
	if(m_activeBackgroupImage)
		m_backgroupImage->SetAttribute("height", h);
#endif
}

void IwNUINew::CPanelNew::SetHeight( const char* h )
{
	this->SetAttribute("height", h);
#ifdef MODIFY_WIDTH_HEIGHT_BGIMAGE
	if(m_activeBackgroupImage)
		m_backgroupImage->SetAttribute("height", h);
#endif
}

bool IwNUINew::CPanelNew::GetVisible()
{
	int visible = true;
	this->GetAttribute("visible", visible);
	return visible != 0 ? true : false;
}

void IwNUINew::CPanelNew::SetVisible( bool visible )
{
	this->SetAttribute("visible", visible);
}